<template>
  <div class="cloud-teller-manage" v-loading="loading" element-loading-text="加载中。。。">
    <div>
      <el-card class='cloud-teller-card'>
        <el-form ref='queryForm' :model='queryForm' size='mini' label-position='top'>
          <el-row :gutter="10">
            <el-col :md='6' :lg='4'>
              <el-form-item label='柜员号' prop='AGENTID'>
                <el-input v-model='queryForm.AGENTID' maxlength="8" placeholder="请输入柜员号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :md='6' :lg='4'>
              <el-form-item label='柜员姓名' prop='AGENTNAME'>
                <el-input v-model='queryForm.AGENTNAME' maxlength="8" placeholder="请输入柜员姓名"></el-input>
              </el-form-item>
            </el-col>
            <el-col :md='6' :lg='4'>
              <el-form-item label='交易名称' prop='FLOWTRADE'>
                <el-select v-model='queryForm.FLOWTRADE' filterable>
                  <el-option v-for='item in FLOWNAMEOpions' :key='item.FLOWID' :label='item.FLOWNAME' :value='item.FLOWID'>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :md="3" :lg="2" class="searchBtnMarginTop">
              <el-button type='primary' size='mini' icon='el-icon-search' @click="queryModel('search')">查询</el-button>
            </el-col>
            <el-col :md="3" :lg="2" class="searchBtnMarginTop">
              <el-button type='warning' size='mini' icon='el-icon-refresh' @click="clearForm('queryForm')">重置</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card style="margin-top: 10px">
      <el-col :lg="3" :md="2" v-if="btnPermission('Button_Warning_Add')">
              <el-button type="primary" size="mini" @click="addDialogShow" icon='el-icon-plus' >新增</el-button>
          </el-col>
        <el-table ref="tableData" :data='tableDataPage' border min-height="400" width='100%' class="tableMarginTop" header-row-class-name="tableHeaderClass" highlight-current-row>
          <el-table-column prop='AGENTID' label='柜员工号'></el-table-column>
          <el-table-column prop='AGENTNAME' label='柜员姓名'></el-table-column>
          <el-table-column prop='BRANCH' label='机构ID'></el-table-column>
          <!-- <el-table-column prop='CENTERNAME' label='机构名称' width='180'></el-table-column> -->
          <el-table-column prop='FLOWTRADE' label='交易码'></el-table-column>
          <el-table-column prop='FLOWTRADENAME' label='交易名称'></el-table-column>
          <!-- <el-table-column prop='REMARK1' label='维护日期'></el-table-column>
          <el-table-column prop='REMARK2' label='维护人'></el-table-column> -->
          <el-table-column label='操作' align="center" fixed="right" width="150">
            <template slot-scope="scope">
                <el-button size="mini" type="primary" @click="handleClickDialog(scope.row)">维护</el-button>
                <el-button size="mini" type="danger" @click="handleDel(scope.row)">删除</el-button>
</template>
          </el-table-column>
        </el-table>
        <el-pagination style="text-align:right;margin-top:20px;" v-show="this.tableData" :current-page="currentPage" background :page-size="pageSize"
          @current-change="changePage" layout="total, prev, pager, next, jumper" :total="tableData.length">
        </el-pagination>
      </el-card>

      <keep-alive>
        <component :is='dialogList.addTellerTransaction' :option='addDialogOptions' @refreshTable="queryModel('search')"></component>
      </keep-alive>
      <keep-alive>
        <component :is='dialogList.tellerTransaction' :option='dialogOptions' @refreshTable="queryModel('search')"></component>
      </keep-alive>
    </div>

  </div>
</template>

<script>
  import addTellerTransaction from "./dialog/addTellerTransaction";
  import tellerTransaction from "./dialog/tellerTransaction";
  import selectTree from "@/components/selectTree2/";
  import toolBox from "@/CTManage/utils/toolBox";
  import getGlobalParams from '@/common/utils/getGlobalParams';
  //通讯相关
  import request from "@/common/utils/requestCT";
  import cloudExceptionTranQuery from "@/message/CTManage/cloud-exception-transaction/cloud-exception-transaction-query";
  import cloudExceptionTranDel from "@/message/CTManage/cloud-exception-transaction/cloud-exception-transaction-del";
  import transactionNameQuery from "@/message/shared/transaction-name-query";
  export default {
    name: "cloud-teller-manage",
    components: {
      selectTree
    },
    data() {
      return {
        //页面公用
        loading: false,
        //表格
        tableTotal: 0,
        tableData: [{
          AGENTID: '123'
        }],
        currentPage: 1,
        pageSize: getGlobalParams.get("PageSize"),
        delButtonShow: false,
        updateButtonShow: false,
        queryForm: {
          AGENTID: '',
          AGENTNAME: '',
          FLOWTRADE: ''
        },
        currentRow: [],
        telleridSelection: [],
        dialogList: {
          tellerTransaction,
          addTellerTransaction
        },
        dialogOptions: {
          isShow: false,
          font: '',
          currentRow: {}
        },
        addDialogOptions:{
            isShow: false,
          font: '',
          currentRow: {}
        },
        FLOWNAMEOpions: []
      };
    },
    mounted() {
      this.queryModel();
      this.transactionNameQuery();
    },
    computed: {
      tableDataPage() {
        return this.tableData.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize);
      }
    },
    methods: {
      // 获取交易名称方法
      async transactionNameQuery() {
        this.loading = true;
        this.tableData = [];
        this.tableTotal = 0;
        let resBody = new transactionNameQuery();
        let response = await request(resBody);
        this.loading = false;
        if (response.SYS_HEAD.ReturnCode == "000000") {
          // console.log(response.RSP_BODY.resultSet)
          this.FLOWNAMEOpions = response.RSP_BODY.resultSet;
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          });
        }
      },
      // 点击新增按钮事件
      addDialogShow(row) {
        // console.log(row)
        this.addDialogOptions.currentRow = row;
        this.addDialogOptions.isShow = !this.addDialogOptions.isShow;
      },
      // 点击修改按钮事件
      handleClickDialog(row) {
        // console.log(row)
        this.dialogOptions.currentRow = row;
        this.dialogOptions.isShow = !this.dialogOptions.isShow;
      },
      changePage(val) {
        this.currentPage = val
      },
      clearForm(item) {
        this.$refs["" + item].resetFields();
      },
      async queryModel(data) {
        if(data == 'search'){
          this.currentPage = 1;
        }
        this.loading = true;
        this.tableData = [];
        this.tableTotal = 0;
        let resBody = new cloudExceptionTranQuery();
        resBody.data.AGENTID = this.queryForm.AGENTID;
        resBody.data.AGENTNAME = this.queryForm.AGENTNAME;
        resBody.data.FLOWTRADE = this.queryForm.FLOWTRADE;
        resBody.QueryPageNo = this.currentPage;
        resBody.QueryRowNum = this.pageSize;
        let response = await request(resBody);
        this.loading = false;
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.tableData = response.RSP_BODY.resultSet;
          this.tableTotal = response.RSP_BODY.total * 1
          //  || response.QUERY_INFO_HEAD.QueryAllDataCount;
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          });
        }
      },
      formatData(row, column) {
        // console.log(row, column)
        return this.FLOWNAMEOpions[row[column.property]]
      },
      handleDel(row) {
        // console.log(row)
        this.$confirm("此操作将永久删除" + row.AGENTNAME + "的关联关系 是否继续？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(() => {
            this.delFun(row);
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
          });
      },
      async delFun(row) {
        this.loading = true;
        let resBody = new cloudExceptionTranDel();
        resBody.data.AGENTID = row.AGENTID
        resBody.data.CENTERID = row.CENTERID
        resBody.data.FLOWTRADE = row.FLOWTRADE
        resBody.data.BRANCH = row.BRANCH
        let response = await request(resBody);
        this.loading = false;
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.$message({
            type: "success",
            message: "云柜员例外交易关系解除成功!"
          });
          this.queryModel('search');
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          });
        }
      },
      // handleSizeChange() {
      //   this.queryModel('search');
      // },
    },
    async created() {}
  };
</script>


<style lang="scss" scoped>
  .el-date-editor.el-input {
    width: 100% !important;
  }
  .el-card {
    overflow: inherit;
  }
</style>
